import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-08-15
 * Time: 11:40
 */
public class MyQueue {
    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    //构造方法
    public MyQueue() {
        this.stack1 = new Stack<>();
        this.stack2 = new Stack<>();
    }

    //将元素 x 推到队列的末尾
    public void push(int x) {
        stack1.push(x);
    }

    //从队列的开头移除并返回元素
    public int pop() {
        if (empty()) {
            return -1;
        }
        if (stack2.empty()) {
            while (!stack1.empty()) {
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }

    //返回队列开头的元素
    public int peek() {
        if (empty()) {
            return -1;
        }
        if (stack2.empty()) {
            while (!stack1.empty()) {
                stack2.push(stack1.pop());
            }
        }
        return stack2.peek();
    }

    //如果队列为空，返回 true ；否则，返回 false
    public boolean empty() {
        return stack1.empty() && stack2.empty();
    }
}
